#include"Heap.h"
void test01()
{
	//测试
	HP php;
	//插入并打印
	HPInit(&php);
	HPPush(&php, 5);
	HPPrint(&php);
	HPPush(&php, 3);
	HPPrint(&php);
	HPPush(&php, 2);
	HPPrint(&php);
	HPPush(&php, 7);
	HPPrint(&php);
	HPPush(&php, 4);
	HPPrint(&php);
	HPPush(&php, 1);
	HPPrint(&php);
	HPPush(&php, 6);
	HPPrint(&php);
	HPPush(&php, 8);
	HPPrint(&php);
	HPPush(&php, 9);
	HPPrint(&php);
	HPPush(&php, 10);
	HPPrint(&php);
	//删除并打印
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPPop(&php);
	HPPrint(&php);
	HPDestory(&php);
}
void test02()
{
	//堆排序
	HP php;
	HPInit(&php);
	CreateNDate();
	const char* file = "data.txt";
	FILE* pf = fopen(file, "r");
	if (pf == NULL)
	{
		perror("fopen fail");
		return;
	}
	int val = 0;
	while (!feof(pf))
	{
		if(fscanf(pf,"%d",&val)==1)
			HPPush(&php, val);
	}
	HeapSort(php.arr,10);
	HPPrint(&php);
	fclose(pf);
}
void test03()
{
	//TopK
	HP php;
	HPInit(&php);
	CreateNDate();
	const char* file = "data.txt";
	FILE* pf = fopen(file, "r");
	if (pf == NULL)
	{
		perror("fopen fail");
		return;
	}
	int val = 0;
	while (!feof(pf))
	{
		if (fscanf(pf, "%d", &val) == 1)
			HPPush(&php, val);
	}
	PrintTopK(3);
	PrintTopK(1);
	fclose(pf);
}
int main()
{
	test01();
	test02();
	test03();
	return 0;
}